package net.mikoo.seals.agent.biz.services.impl;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.mikoo.seals.agent.biz.mapper.client.DevicesMapper;
import net.mikoo.seals.agent.biz.services.DevicesServices;
import net.mikoo.seals.agent.common.BaseServices;
import net.mikoo.seals.agent.common.PageModel;
import net.mikoo.seals.agent.common.enums.DevicesStatusEnum;
import net.mikoo.seals.agent.common.exception.ParametersException;
import net.mikoo.seals.agent.model.Devices;
import net.mikoo.seals.agent.model.DevicesQuery;



@Service
public class DevicesServicesImpl extends BaseServices implements DevicesServices {
	
	Logger logger = LoggerFactory.getLogger(CompanyServicesImpl.class);

	@Autowired
	private DevicesMapper devicesMapper;
	
	@Override
	public void save(Devices devices) {
		
		if(devices == null){
			throw new ParametersException("devices is null!");
		}
		
		if(devices.getCompanyId() == null) {
			throw new ParametersException("请选择公司");
		}
		
		if(StringUtils.isBlank(devices.getDevicesId())) {
			throw new ParametersException("请输入设备编号");
		}
		
		devices.setUseTimes(0);
		devices.setApplyTimes(0);
		devices.setDevicesStatus(DevicesStatusEnum.WAIT_BIND.code());
		devices.setCreateTime(new Date());
		devicesMapper.insert(devices);
	}

	@Override
	public void modify(Devices devices) {
		
		if(devices == null){
			throw new ParametersException("devices is null!");
		}
		devicesMapper.delete(devices);
	}
	
	@Override
	public Devices getInfoById(Long DevicesId) {
		
		if(DevicesId == null){
			throw new ParametersException("DevicesId is null!");
		}
		
		Devices Devices = devicesMapper.selectInfoById(DevicesId);
		return Devices;
	}
	
	
	
	@Override
	public PageModel<Devices> getPageByQuery(DevicesQuery query) {
		
		
		List<Devices> datas = devicesMapper.selectByQueryToPage(query);
		Integer total = devicesMapper.countByQueryToPage(query);
		PageModel<Devices> pm = new PageModel<Devices>(total,datas);
		return pm;
	}

	@Override
	public void deleteById(Long devicesId) {
		// TODO Auto-generated method stub
		
	}

	
}
